home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_203 / examples / misc / manxpcbug.asm < prev    next >
Assembly Source File  |  1992-05-06  |  2KB  |  58 lines

  1. ;                 MANX to NORMAL PC Addressing Conversion
  2. ;
  3. ;  Amoung many other deficencies, the Manx C compiler does not correctly
  4. ;  compute PC relative addressing modes. Unfortunately, the compiler tends
  5. ;  to use this mode when it compiles C switches. If you were to take the
  6. ;  assembly listing as output by the Manx compiler and assemble it with
  7. ;  another company's assembler, the resulting code would not run properly.
  8. ;  The reason that Manx compiled code DOES WORK with the Manx assembler is
  9. ;  because the assembler is written incorrectly as well, and in this case,
  10. ;  two wrongs just happen to make a right. Here is a typical C switch as
  11. ;  output by the Manx compiler.
  12.  
  13. ;.L1 move.w   Number0to2,d0 ;there are 3 cases in the switch for this example
  14. ;    moveq    #-1,d1        ;returns d1 = the switch taken
  15. ;    bra      .L3
  16. ;.L2 dc.w     .0-.L4-2      ;CASE 0
  17. ;    dc.w     .1-.L4-2      ;CASE 1
  18. ;    dc.w     .2-.L4-2      ;CASE 2
  19. ;.L3 cmpi.w   #3,d0         ;check that the number is from 0 to 2
  20. ;    bcc      .L5
  21. ;    add.w    d0,d0
  22. ;    move.w   .L2(pc,d0.w),d0
  23. ;.L4 jmp      (pc,d0.w)     ;this LOOKS like 0(pc,d0.w) to another assembler
  24.                             ;but Manx translates it as .L4+2(pc,d0.w)
  25. ;.L5 moveq    #0,d0
  26. ;    rts
  27. ;.0  moveq    #0,d1
  28. ;    bra.s    .L5
  29. ;.1  moveq    #1,d1
  30. ;    bra.s    .L5
  31. ;.2  moveq    #2,d1
  32. ;    bra.s    .L5
  33.  
  34. ; The correct (i.e. NOT MANX WAY) code should be as follows:
  35.  
  36. .L1 move.w   Number0to2,d0
  37.     moveq    #-1,d1
  38.     bra.s    .L3
  39. .L2 dc.w     .0-.L4-2         ;CASE 0
  40.     dc.w     .1-.L4-2         ;CASE 1
  41.     dc.w     .2-.L4-2         ;CASE 2
  42. .L3 move.w   d0,d1
  43.     subq.w   #3,d1            ;faster
  44.     bcc.s    .L5
  45.     add.w    d0,d0
  46.     move.w   .L2(pc,d0.w),d0
  47. .L4 jmp      .L4+2(pc,d0.w)   ;This is correct
  48. .L5 moveq    #0,d0
  49.     rts
  50. .0  moveq    #0,d1
  51.     bra.s    .L5
  52. .1  moveq    #1,d1
  53.     bra.s    .L5
  54. .2  moveq    #2,d1
  55.     bra.s    .L5
  56.  
  57. Number0to2 dc.w 2
  58.